home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / Vk / VkNameList.z / VkNameList
Encoding:
Text File  |  2002-10-03  |  17.6 KB  |  529 lines

  1.  
  2.  
  3.  
  4. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      VkNameList - A class that supports and manipulates lists of strings
  10.  
  11. HHHHEEEEAAAADDDDEEEERRRR FFFFIIIILLLLEEEE
  12.      #include <Vk/VkNameList.h>
  13.  
  14. PPPPUUUUBBBBLLLLIIIICCCC PPPPRRRROOOOTTTTOOOOCCCCOOOOLLLL SSSSUUUUMMMMMMMMAAAARRRRYYYY
  15.    CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr////DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  16.            VkNameList(void);
  17.  
  18.            VkNameList(const VkNameList& givenList);
  19.  
  20.            VkNameList(char* name);
  21.  
  22.            void ~VkNameList(void);
  23.  
  24.  
  25.  
  26.    AAAAddddddddiiiinnnngggg aaaannnndddd RRRReeeemmmmoooovvvviiiinnnngggg IIIItttteeeemmmmssss
  27.            void add(char* name);
  28.  
  29.            void add(const VkNameList& givenList);
  30.  
  31.            void getIndex(const char* name);
  32.  
  33.            void remove(char* name);
  34.  
  35.            void remove(int index, int count=1);
  36.  
  37.            VkNameList& operator=(const VkNameList& givenList);
  38.  
  39.  
  40.  
  41.    MMMMaaaannnniiiippppuuuullllaaaattttiiiinnnngggg TTTThhhheeee LLLLiiiisssstttt
  42.            void sort(void);
  43.  
  44.            void reverse(void);
  45.  
  46.            void removeDuplicates(void);
  47.  
  48.  
  49.  
  50.    AAAAcccccccceeeessssssss FFFFuuuunnnnccccttttiiiioooonnnnssss
  51.            int size(void);
  52.  
  53.            int exists(char* name);
  54.  
  55.            char* operator[](int index);
  56.  
  57.            VkNameList operator[](char* subString);
  58.  
  59.            int operator==(const VkNameList& givenList);
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  71.  
  72.  
  73.  
  74.            char* mostCommonString(void);
  75.  
  76.            VkNameList* completeName(char* name,
  77.                                     char&* completedName,
  78.                                     int& nMatching);
  79.  
  80.            char** operator char **(void);
  81.  
  82.            XmStringTable operator unsigned char **(void);
  83.  
  84.            char*  getString(int index);
  85.  
  86.            char*  getSubStrings(char *subString);
  87.  
  88.            char** getStringTable();
  89.  
  90.            XmStringTable getXmStringTable();
  91.  
  92.            static void freeXmStringTable (XmStringTable);
  93.  
  94.  
  95.  
  96. CCCCLLLLAAAASSSSSSSS DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  97.           VkNameList provides a convenient way to maintain a list of character
  98.           strings. Strings can be added or removed individually, the list can
  99.           be sorted or reversed, duplications can be removed, the best
  100.           completion of a substring can be found, the most common occurrence
  101.           can be computed, and so on. The list can also be automatically
  102.           converted to a XmStringTable, making this a useful class for use
  103.           with Motif widgets that require a list of compound strings.
  104.  
  105.           Some of the VkNameList operators allocate memory that must later be
  106.           freed by the caller. This can be counter-intuitive, and a source of
  107.           memory leaks.  To avoid that, alternate conventional functions are
  108.           also provided.  The conventional functions make it more clear that
  109.           there is something to be freed.  In one case (_g_e_t_S_u_b_S_t_r_i_n_g_s()), the
  110.           conventional function is also considerably more efficient.
  111.  
  112.           The operators to be careful of are:  _o_p_e_r_a_t_o_r[](_i_n_t) (prefer
  113.           getString(int)); _o_p_e_r_a_t_o_r[](_c_h_a_r*) (prefer getSubStrings(char*));
  114.           _o_p_e_r_a_t_o_r _c_h_a_r**() (prefer getStringTable()); _o_p_e_r_a_t_o_r
  115.           _X_m_S_t_r_i_n_g_T_a_b_l_e() (prefer getXmStringTable());
  116.  
  117.  
  118. FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNNSSSS
  119.    VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt(((())))
  120.            VkNameList(void);
  121.  
  122.            VkNameList(char* name);
  123.  
  124.            VkNameList(const VkNameList& givenList);
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  137.  
  138.  
  139.  
  140.           Initialize a VkNameList object. The first form initializes an empty
  141.           list, while the second allows allows an initial member of the list
  142.           to be specified. The copy constructor produces a clone of an
  143.           existing VkNameList object.
  144.  
  145.  
  146.    ~~~~VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt(((())))
  147.            void ~VkNameList(void);
  148.  
  149.  
  150.           Free all memory allocated by a VkNameList object.
  151.  
  152.  
  153.    aaaadddddddd(((())))
  154.            void add(char *item);
  155.  
  156.            void add(const VkNameList& list);
  157.  
  158.  
  159.           Add an item or a VkNameList to the list.
  160.  
  161.  
  162.    ggggeeeettttIIIInnnnddddeeeexxxx(((())))
  163.            int getIndex(const char *item) const;
  164.  
  165.  
  166.           Gets the index of the first occurrence of the given item from the
  167.           list.  If the item does not exist, the index returned is -1.
  168.  
  169.  
  170.    rrrreeeemmmmoooovvvveeee(((())))
  171.            void remove(char *item);
  172.  
  173.  
  174.           Remove the first occurrence, if any, of the given item from the
  175.           list.
  176.  
  177.  
  178.    rrrreeeemmmmoooovvvveeee(((())))
  179.            void remove(int index, count=1);
  180.  
  181.  
  182.           Remove the items _i_n_d_e_x through _i_n_d_e_x+_c_o_u_n_t-_1 from the list.  _C_o_u_n_t
  183.           items, beginning with a named item, can be removed with the idiom
  184.           _r_e_m_o_v_e(_g_e_t_I_n_d_e_x(_i_t_e_m),_c_o_u_n_t);
  185.  
  186.  
  187.    ssssoooorrrrtttt(((())))
  188.            void sort(void);
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  203.  
  204.  
  205.  
  206.           Sort the items on the list alphanumerically.
  207.  
  208.  
  209.    rrrreeeevvvveeeerrrrsssseeee(((())))
  210.            void reverse(void);
  211.  
  212.  
  213.           Reverse the order of the items on the list.
  214.  
  215.  
  216.    rrrreeeemmmmoooovvvveeeeDDDDuuuupppplllliiiiccccaaaatttteeeessss(((())))
  217.            void removeDuplicates(void);
  218.  
  219.  
  220.           Remove all exact duplicates from the list.
  221.  
  222.  
  223.    ssssiiiizzzzeeee(((())))
  224.            int size(void);
  225.  
  226.  
  227.           Returns the number of elements in the list.
  228.  
  229.  
  230.    eeeexxxxiiiissssttttssss(((())))
  231.            int exists(char *item);
  232.  
  233.  
  234.           Returns non-zero if the specified string is a member of the list.
  235.  
  236.  
  237.  
  238.    ooooppppeeeerrrraaaattttoooorrrr====(((())))
  239.            VkNameList& operator=(const VkNameList&);
  240.  
  241.  
  242.           Assign the members of one list to another.  Note that this frees any
  243.           strings that were in the old object.  Any references to them, such
  244.           as those returned by a previous call to _o_p_e_r_a_t_o_r _c_h_a_r **(), now
  245.           point to free'd memory.
  246.  
  247.  
  248.    ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](((())))
  249.            char* operator[](int index);
  250.  
  251.  
  252.           Retrieve a copy of an item from the list by index.  The returned
  253.           string must be freed by the caller.
  254.  
  255.           For clarity in the application code, _g_e_t_S_t_r_i_n_g(_i_n_t _i_n_d_e_x) is
  256.           preferred.
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  269.  
  270.  
  271.  
  272.    ggggeeeettttSSSSttttrrrriiiinnnngggg(((())))
  273.            char* getString(int index);
  274.  
  275.                Retrieve a copy of an item from the list by index.
  276.                The returned string must be freed by the caller.
  277.  
  278.  
  279.  
  280.    ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](((())))
  281.            VkNameList operator[](char* substring);
  282.  
  283.  
  284.           Return a list of items that match the given substring.  The returned
  285.           object must be delete'd by the caller.
  286.  
  287.           Both for clarity in the application code, and for efficiency,
  288.           _g_e_t_S_u_b_S_t_r_i_n_g_s(_c_h_a_r *) is preferred.
  289.  
  290.  
  291.    ggggeeeettttSSSSuuuubbbbSSSSttttrrrriiiinnnnggggssss(((())))
  292.            VkNameList* getSubStrings(char* substring);
  293.  
  294.  
  295.           Return a pointer to a list of items that match the given substring.
  296.           The returned _V_k_N_a_m_e_L_i_s_t must be delete'd by the caller.
  297.  
  298.  
  299.    ooooppppeeeerrrraaaattttoooorrrr========(((())))
  300.            int operator==(const VkNameList&);
  301.  
  302.  
  303.           Text for equivalence of two VkNameList objects. The lists must have
  304.           identical contents in the same order for the test to return success.
  305.  
  306.  
  307.    mmmmoooossssttttCCCCoooommmmmmmmoooonnnnSSSSttttrrrriiiinnnngggg(((())))
  308.            char* mostCommonString(void);
  309.  
  310.  
  311.           Return a copy of the most common string in a list.  The returned
  312.           string must be freed by the caller.
  313.  
  314.  
  315.    ccccoooommmmpppplllleeeetttteeeeNNNNaaaammmmeeee(((())))
  316.            VkNameList* completeName(char  *name,
  317.                                     char &*completed name,
  318.                                     int&   numMatching);
  319.  
  320.  
  321.           Given a string, this function returns a VkNameList object containing
  322.           all strings in the original list that could be completions of the
  323.           given string. Upon returning, the _c_o_m_p_l_e_t_e_d_N_a_m_e argument contains
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  335.  
  336.  
  337.  
  338.           the matched substring common to all members of the returned list.
  339.           Finally, the _n_u_m_M_a_t_c_h_i_n_g reports the number of matched elements.
  340.  
  341.  
  342.    ooooppppeeeerrrraaaattttoooorrrr(((())))
  343.            char** operator char **(void);
  344.  
  345.  
  346.           This operator returns a pointer to the members of a _V_k_N_a_m_e_L_i_s_t
  347.           object as as an array of strings.  The strings in the returned array
  348.           _M_U_S_T _N_O_T be freed by the caller.  The array itself must be freed by
  349.           the caller.
  350.  
  351.           For clarity in the application code, _g_e_t_S_t_r_i_n_g_T_a_b_l_e() is preferred.
  352.  
  353.  
  354.    ggggeeeettttSSSSttttrrrriiiinnnnggggTTTTaaaabbbblllleeee(((())))
  355.            char** getStringTable(void);
  356.  
  357.  
  358.           This operator returns a pointer to the members of a _V_k_N_a_m_e_L_i_s_t
  359.           object as as an array of strings.  The strings in the returned array
  360.           _M_U_S_T _N_O_T be freed by the caller.  The array itself must be freed by
  361.           the caller.
  362.  
  363.  
  364.    ooooppppeeeerrrraaaattttoooorrrr(((())))
  365.            XmStringTable operator unsigned char **(void);
  366.  
  367.  
  368.           This operator provides access to the members of a _V_k_N_a_m_e_L_i_s_t object
  369.           as as an array of compound strings.  The returned XmStringTable must
  370.           be freed by the caller.  (See _f_r_e_e_X_m_S_t_r_i_n_g_T_a_b_l_e).
  371.  
  372.           For clarity in the application code, _g_e_t_X_m_S_t_r_i_n_g_T_a_b_l_e() is
  373.           preferred.
  374.  
  375.  
  376.    ggggeeeettttXXXXmmmmSSSSttttrrrriiiinnnnggggTTTTaaaabbbblllleeee(((())))
  377.            XmStringTable getXmStringTable(void);
  378.  
  379.  
  380.           This operator provides access to the members of a _V_k_N_a_m_e_L_i_s_t object
  381.           as as an array of compound strings.  The returned XmStringTable must
  382.           be freed by the caller.  (See _f_r_e_e_X_m_S_t_r_i_n_g_T_a_b_l_e).
  383.  
  384.  
  385.    ffffrrrreeeeeeeeXXXXmmmmSSSSttttrrrriiiinnnnggggTTTTaaaabbbblllleeee
  386.            static void freeXmStringTable (XmStringTable)
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  401.  
  402.  
  403.  
  404.           This function frees the memory returned by _X_m_S_t_r_i_n_g_T_a_b_l_e _o_p_e_r_a_t_o_r
  405.           (), or by _g_e_t_X_m_S_t_r_i_n_g_T_a_b_l_e().
  406.  
  407. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  408.      The following example uses a VkNameList to construct a list
  409.      incrementally, and display the resulting list in reverse sorted order in
  410.      a Motif XmList widget.
  411.  
  412.  
  413.            #include <Vk/VkApp.h>
  414.            #include <Vk/VkSimpleWindow.h>
  415.            #include <Xm/List.h>
  416.            #include <Vk/VkNameList.h>
  417.  
  418.            // Define a top-level window class
  419.  
  420.            class MyWindow: public VkSimpleWindow {
  421.  
  422.             protected:
  423.  
  424.               Widget _list;    // Hang on to widget as a data member
  425.  
  426.             public:
  427.  
  428.               MyWindow ( const char *name );
  429.               ~MyWindow();
  430.               virtual const char* className();  // Identify this class
  431.            };
  432.  
  433.            // The MyWindow constructor provides a place in which
  434.            // to create a widget tree to be installed as a
  435.            // "view" in the window.
  436.  
  437.            MyWindow::MyWindow ( const char *name ) :
  438.                             VkSimpleWindow ( name )
  439.            {
  440.               _list =  XmCreateList ( mainWindowWidget(),
  441.                                       "list", NULL, 0 );
  442.  
  443.               // Create a name list object
  444.  
  445.               VkNameList *items = new VkNameList();
  446.  
  447.               // Add some items
  448.  
  449.               items->add("One");
  450.               items->add("Two");
  451.               items->add("Three");
  452.               items->add("Four");
  453.               items->add("One");
  454.  
  455.               items->removeDuplicates();  // Get rid of duplications
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))                                                  VVVVkkkkNNNNaaaammmmeeeeLLLLiiiisssstttt((((3333xxxx))))
  467.  
  468.  
  469.  
  470.               items->sort();              // sort the list
  471.               items->reverse();           // Now reverse it
  472.  
  473.               // Display the items in the list widget
  474.  
  475.               XtVaSetValues(_list,
  476.                             XmNitems, (XmStringTable) (*items),
  477.                             XmNitemCount, items->size(),
  478.                             NULL);
  479.  
  480.               addView(_list);
  481.            }
  482.  
  483.            const char * MyWindow::className()
  484.            {
  485.               return "MyWindow";
  486.            }
  487.  
  488.            MyWindow::~MyWindow()
  489.            {
  490.               // Empty
  491.            }
  492.  
  493.            // Main driver. Just instantiate a VkApp and a
  494.            // top-level window, "show" the window and then
  495.            // "run" the application.
  496.  
  497.            void main ( int argc, char **argv )
  498.            {
  499.               VkApp     *app = new VkApp("Hello", &argc, argv);
  500.               MyWindow  *win = new MyWindow("hello");
  501.  
  502.               win->show();
  503.               app->run();
  504.            }
  505.  
  506.  
  507.  
  508. KKKKNNNNOOOOWWWWNNNN CCCCLLLLAAAASSSSSSSSEEEESSSS TTTTHHHHAAAATTTT UUUUSSSSEEEE TTTTHHHHIIIISSSS CCCCLLLLAAAASSSSSSSS
  509.      VkCompletionField
  510.  
  511. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  512.      VkCompletionField
  513.      _V_i_e_w_K_i_t _P_r_o_g_r_a_m_m_e_r'_s _G_u_i_d_e
  514.      _T_h_e _X _W_i_n_d_o_w _S_y_s_t_e_m, DEC Press, Bob Sheifler and Jim Gettys
  515.      _T_h_e _X _W_i_n_d_o_w _S_y_s_t_e_m _T_o_o_l_k_i_t, DEC Press, Paul Asente and Ralph Swick
  516.      _T_h_e _O_S_F/_M_o_t_i_f _P_r_o_g_r_a_m_m_e_r_s _R_e_f_e_r_e_n_c_e, Prentice Hall, OSF
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.